<template>
  <div class="components-container">
    <div class="header-form" style="margin-bottom:5px;">
      <!-- <div class="layui-inline">
        <label class="layui-form-label">炉子编号</label>
        <div class="layui-input-inline">
          <el-input v-model="selectData.CrenameLike" placeholder="请输入火化炉编号"></el-input>
        </div>
      </div> -->
      <!-- <div class="layui-inline">
        <label class="layui-form-label">逝者姓名</label>
        <div class="layui-input-inline">
          <el-input v-model="selectData.RegnameLike" placeholder="请输入逝者姓名"></el-input>
        </div>
      </div> -->
      <div class="layui-inline">
        <label class="layui-form-label">收费项目</label>
        <div class="layui-input-inline">
          <el-select v-model="selectData.Crhoprusr" placeholder="请选择收费项目" style="width:100%" @change="btnSearch">
            <el-option v-for="item in creUSES" :key="item.STAID" :label="item.STANAME" :value="item.STAID">
            </el-option>
          </el-select>
        </div>
      </div>
      <!-- <div class="layui-inline">
        <label class="layui-form-label">开始日期</label>
        <div class="layui-input-inline">
          <el-date-picker v-date v-model="selectData.CrhbegdateSta" type="date" placeholder="请选择日期">
          </el-date-picker>
        </div>
      </div>
      <div class="layui-inline">
        <label class="layui-form-label">结束日期</label>
        <div class="layui-input-inline">
          <el-date-picker v-date v-model="selectData.CrhbegdateEnd" type="date" placeholder="请选择日期">
          </el-date-picker>
        </div>
      </div> -->
      <el-button type="primary" @click="btnSearch" :loading="this.$store.state.isloading">搜索</el-button>
      <el-button @click="btnRepeat">重置</el-button>
    </div>
    <!-- 功能列表 -->
    <div>
      <ul class="toolList">
        <li><el-button type="primary" @click="btnSearch" :loading="this.$store.state.isloading">刷新</el-button></li>
        <li v-if="btnShow(item.BTNVALUE)" v-for="(item, index) in $store.state.btnListCommon" @click="operate(item.BTNVALUE)">
          <el-button type="primary" :value="item.BTNSHOWNAME" v-text="item.BTNSHOWNAME"></el-button>
        </li>
      </ul>
    </div>
    <!-- 数据列表 -->
    <dataTable :headList="headList" :dataList="dataList" :pageOrder="pageOrder" @pageChange="pageChange" @selectRow="selectRow"></dataTable>
    <!--操作弹窗  -->
    <subsidySetMain ref="dialog" @refreshData="getData"> </subsidySetMain>
    <staEndUse ref="useMain" @refreshData="getData"></staEndUse>
  </div>
</template>
<style rel="stylesheet/scss" lang="scss" scoped>
@import "src/styles/common.scss";

</style>
<script>
import subsidySetMain from "./subsidySetMain";
import apiBase from "@/api/apiBase.js";
import dataTable from "@/components/Table/DataTable";
import { formatDate, timeStringToDate } from "@/utils/date.js";
import { manage } from "@/mixins/managePage.js";
import staEndUse from "../basic/staEndUse";

const ADD = "新增";
const MODIFY = "修改";
const DELETE = "删除";
const INFO = "详情";
const close = "禁用";
const opens = "启用";
export default {
  name: "creUse",
  mixins: [manage],
  data() {
    return {
      selectData: {},
      creUSES: [],
    };
  },
  methods: {
    //功能操作
    operate(order) {
      this.order = order;
      switch (this.order) {
        case ADD:
          this.$refs.dialog.open(this.order);
          break;
        case MODIFY:
          this.$refs.dialog.open(this.order,this.currentRow.SBSID);
          break;
        case INFO:
          this.$refs.dialog.open(this.order,this.currentRow.SBSID);
          break;
         case DELETE:
          this.dataDelete();
          break;
        case close:
          this.$refs.useMain.open(this.order, this.currentRow.SBSID);
          break;
        case opens:
           this.$refs.useMain.open('取消禁用', this.currentRow.SBSID);
          break;
        default:
      }
    },
    btnShow(val){
      if(this.currentRow){
        status = this.currentRow.SBSSTATUS;
      }
      switch(val){
        case ADD:
          return true;
          break;
        case DELETE:
        case MODIFY:
        case INFO:
          if(this.currentRow) return true;
          break;
        case close:
          return status === 'A';
          break;
        case opens:
           return status === 'B';
          break;
        default:
      }
    },
    //获取表头
    getCreColumn() {
      apiBase.DoService(
        {},
        apiBase.getApiAdress().Column.GetSubsidySetColumns,
        res => {
          this.headList = res.data.content;
        }
      );
    },
    //获取查询数据
    getData() {
      // let Data = JSON.parse(JSON.stringify(this.selectData));
      // Data.CrhbegdateSta = formatDate(Data.CrhbegdateSta, "yyyyMMdd");
      // Data.CrhbegdateEnd = formatDate(Data.CrhbegdateEnd, "yyyyMMdd");
      let Data;
      var data = {
        PageIndex: this.pageOrder.currentPage,
        PageSize: this.pageOrder.pageSize,
        OrderBy: this.pageOrder.orderType,
        OrderByType: this.pageOrder.orderSort,
        Data: Data
      };
      apiBase.DoService(
        data,
        apiBase.getApiAdress().Subsidy.QuerySbs,
        res => {
          this.dataList = res.data.content.OutData;
          this.pageOrder.totalNum = res.data.content.RecordCount;
        }
      );
    },
    //删除
    dataDelete() {
      var data = {
        SBSID: this.currentRow.SBSID
      };
      this.$confirm("此操作将删除该信息, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(callback => {
          apiBase.DoService(
            data,
            apiBase.getApiAdress().Subsidy.DeleteSbs,
            res => {
              this.getData();
              this.$message({
                message: "删除成功！",
                type: "success"
              });
            }
          );
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除"
          });
        });
    },
    //禁用
    close() {
      var data = {
        SBSID: this.currentRow.SBSID
      };
      this.$confirm("此操作将禁用该信息, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(callback => {
          apiBase.DoService(
            data,
            apiBase.getApiAdress().Subsidy.DeleteSbs,
            res => {
              this.getData();
              this.$message({
                message: "禁用成功！",
                type: "success"
              });
            }
          );
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消禁用"
          });
        });
    },
    //启用
    opens() {
      var data = {
        SBSID: this.currentRow.SBSID
      };
      this.$confirm("此操作将启用该信息, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(callback => {
          apiBase.DoService(
            data,
            apiBase.getApiAdress().Subsidy.DeleteSbs,
            res => {
              this.getData();
              this.$message({
                message: "启用成功！",
                type: "success"
              });
            }
          );
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消启用"
          });
        });
    },
    //重置查询
    btnRepeat() {
      this.selectData = {};
      this.getData();
    },
  },

  components: {
    subsidySetMain,
    dataTable,
    staEndUse
  },
  created() {
       this.getCreColumn();
    this.getData();
  }
};
</script>